package com.dv.web.controller.basic;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.BasicVehicle;
import com.dv.driverless.domain.vo.BasicVehicleVo;
import com.dv.driverless.service.IBasicVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆信息表Controller
 *
 * @author ruoyi
 * @date 2023-04-02
 */
@RestController
@RequestMapping("/basic/vehicle")
public class BasicVehicleController extends BaseController
{
    @Autowired
    private IBasicVehicleService basicVehicleService;

    /**
     * 查询车辆信息表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicVehicleVo basicVehicleVo)
    {
        startPage();
        List<BasicVehicleVo> list = basicVehicleService.selectBasicVehicleList(basicVehicleVo);
        return getDataTable(list);
    }

    /**
     * 获取车辆信息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basicVehicleService.selectBasicVehicleById(id));
    }

    /**
     * 新增车辆信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:vehicle:add')")
    @Log(title = "车辆信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicVehicle basicVehicle)
    {
        basicVehicle.setCreateDate(DateUtils.getNowDate());
        return toAjax(basicVehicleService.insertBasicVehicle(basicVehicle));
    }

    /**
     * 修改车辆状态
     */
    @Log(title = "车辆信息表",businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeVehicleStatus(@RequestBody BasicVehicle basicVehicle)
    {
        return toAjax(basicVehicleService.changeBasicVehicle(basicVehicle));
    }

    /**
     * 修改车辆信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:vehicle:edit')")
    @Log(title = "车辆信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicVehicle basicVehicle)
    {
        return toAjax(basicVehicleService.updateBasicVehicle(basicVehicle));
    }

    /**
     * 删除车辆信息表
     */
    @PreAuthorize("@ss.hasPermi('basic:vehicle:remove')")
    @Log(title = "车辆信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basicVehicleService.deleteBasicVehicleByIds(ids));
    }
}
